package com.wowangz.cms.syscore;

import org.apache.ibatis.session.SqlSession;

public class SqlSessionContainer {
	
	private final static  ThreadLocalAnother threadlocal = new ThreadLocalAnother();

	
	public SqlSessionContainer() 
	{
	}


	/**
	 * 获取sqlsession
	 * @return
	 * @throws Exception
	 */
	public SqlSession getSqlSession() 
	{
		SqlSession session = (SqlSession) threadlocal.get();
		return session;
	}
	
	/**
	 * 设置sqlsession
	 * @param session
	 * @throws Exception
	 */
	public void putSqlSession(SqlSession session) 
	{
		  SqlSession sessiontemp = (SqlSession) threadlocal.get();
	      
		  if(sessiontemp==null)
	      {
	        threadlocal.set(session);
	      }
	}

	/**
	 * 移除sqlsession
	 * @throws Exception
	 */
	public void closeSqlSession()  {
		SqlSession session = (SqlSession) threadlocal.get();
		if (session!=null) {
			session.close();
			threadlocal.remove();
		}
	
	}
	

}
